package net.melon.cata.manager.id;

import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;

public class ScaleIDGenerateFactory {

	private static final Map<String,ScaleIDGenerate> cache = new HashMap<String, ScaleIDGenerate>();
	
	private static void reloadGenerators(){
		cache.clear();
		cache.put(ScaleType.HEX.name(), new HexaIDGenerate());
		cache.put(ScaleType.DEC.name(), new DecimalIDGenerate());
	}
	
	public static ScaleIDGenerate get(String key){
		if(cache.isEmpty()){
			reloadGenerators();
		}
		ScaleIDGenerate bean =  cache.get(key.toUpperCase());
		if(bean == null){
			throw new NoSuchElementException("no such scaleIDGenerate named for ["+key+"]");
		}
		return bean;
	}
}
